<cfsetting enablecfoutputonly="true">
<cfcontent type="text/xml">
	<cfobject name="workbookss" component="xls2query">
	<cfset inFile = workbookss.getXlsFile("./jxlrwtest.xls")>
	<cfobject type="Java" action="create" name="Workbook" class="jxl.Workbook">
	<cfset workbookFile = workbookss.getWorkbook(inFile)>

<!--- <cfobject type="Java" action="create" name="XlsToXML" class="jxl.XlsToXML">
 <cfset xml = variables.XlsToXML>
 <cfset wexml = xml.init(os,true)>
 --->

<cfscript>
	startRow = 0;
	maxRows = 0;

//		daXML = createObject("java", "jxl.demo.XML").init(workbook, out,"UTF8", false);

//		xmlBuffer = CreateObject("java","java.lang.String").init(daXM).getBytes();
			//Turn the buffers into input streams
//		xmlInputStream = CreateObject("java","java.io.FileInputStream").init(daFile);

//		workbook = createObject("java", "jxl.Workbook");
		workbook = workbookFile;
		// writeOutput(workbook.getVersion());
//		out = CreateObject("java","java.io.ByteArrayOutputStream").init();
//		osw = CreateObject("java","java.io.OutputStreamWriter").init(out,"UTF8");
//		workbook = createObject("java", "jxl.Workbook");
//		rw = createObject("java", "jxl.demo.ReadWrite").init("C:\workspace\jexcelapi\jxlrwtest.xls","C:\workspace\jexcelapi\jxlrwtestOut.xls");
 //      rw.readWrite();
		//out = CreateObject("java","java.io.OutputStream");
//		daXML = createObject("java", "jxl.demo.XML").init(workbook, out,"UTF8", false);
//		workbook = createObject("java", "jxl.Workbook");
		out = CreateObject("java","java.io.ByteArrayOutputStream").init();
  //  try
  //  {
			osw = CreateObject("java","java.io.OutputStreamWriter").init(out,"UTF8");
      //OutputStreamWriter osw = new OutputStreamWriter(out, encoding);
			bw = CreateObject("java","java.io.BufferedWriter").init(osw);
      //BufferedWriter bw = new BufferedWriter(osw);
      sheets = workbook.getRangeNames();
      bw.write("<?xml version=""1.0"" ?>");
      bw.newLine();
      bw.write("<!DOCTYPE workbook SYSTEM ""formatworkbook.dtd"">");
      bw.newLine();
      bw.newLine();
      bw.write("<workbook>");
      bw.newLine();
      for (sheet = 0; sheet lt workbook.getNumberOfSheets(); sheet = sheet+1)
      {
        s = workbook.getSheet(javaCast("int",sheet));

        bw.write("  <sheet>");
        bw.newLine();
        bw.write("    <name><![CDATA[" & s.getName() & "]]></name>");
        bw.newLine();
      
        //Cell[] row = null;
        //CellFormat format = null;
        //Font font = null;
        if (maxRows eq 0) { maxRows = s.getRows(); }
        for (i = startRow ; (i lt maxRows AND i lt s.getRows()) ; i = i+1)
        {
          bw.write("    <row number=""" & i & """>");
          bw.newLine();
          row = s.getRow(javaCast("int",i));

          for (j = 1 ; j lte arrayLen(row); j = j+1)
          {
            // Remember that empty cells can contain format information
            if ((row[j].getType() neq "") OR
                (row[j].getCellFormat() neq ""))
            {
              format = row[j].getCellFormat();
              bw.write("      <col number=""" & j & """>");
              bw.newLine();
              bw.write("        <data>");
              bw.write("<![CDATA["&row[j].getContents()&"]]>");
              bw.write("</data>");
              bw.newLine();     

              if (row[j].getCellFormat() neq "")
              {
                bw.write("        <format wrap=""" & format.getWrap() & """");
                bw.newLine();
                bw.write("                align=""" & 
                         format.getAlignment().getDescription() & """");
                bw.newLine();
                bw.write("                valign=""" & 
                         format.getVerticalAlignment().getDescription() & """");
                bw.newLine();
                bw.write("                orientation=""" & 
                         format.getOrientation().getDescription() & """");
                bw.write(">");
                bw.newLine();

                // The font information
                font = format.getFont();
                bw.write("          <font name=""" & font.getName() & """");
                bw.newLine();
                bw.write("                point_size=""" & 
                         font.getPointSize() & """");
                bw.newLine();
                bw.write("                bold_weight=""" & 
                         font.getBoldWeight() & """");
                bw.newLine();
                bw.write("                italic=""" & font.isItalic() & """");
                bw.newLine();
                bw.write("                underline=""" & 
                         font.getUnderlineStyle().getDescription() & """");
                bw.newLine();
                bw.write("                colour=""" & 
                         font.getColour().getDescription() & """");
                bw.newLine();
                bw.write("                script=""" & 
                         font.getScriptStyle().getDescription() & """");
                bw.write(" />");
                bw.newLine();


                // The cell background information
                /*
                not sure how to get this "Colour" info
                if (format.getBackgroundColour() neq Colour.DEFAULT_BACKGROUND OR
                    format.getPattern()          neq Pattern.NONE)
                */
                if (1 eq 1)
                {
                  bw.write("          <background colour=""" & 
                           format.getBackgroundColour().getDescription() & """");
                  bw.newLine();
                  bw.write("                      pattern=""" & 
                           format.getPattern().getDescription() & """");
                  bw.write(" />");
                  bw.newLine();
                }


                // The cell border, if it has one
/*
Not sure how to get the Border or BorderLineStyle info
                 if (format.getBorder(Border.TOP  )  neq BorderLineStyle.NONE or
                    format.getBorder(Border.BOTTOM) neq BorderLineStyle.NONE or
                    format.getBorder(Border.LEFT)   neq BorderLineStyle.NONE or
                    format.getBorder(Border.RIGHT)  neq BorderLineStyle.NONE)
                {
 */                  
                 if (1 neq 1) 
                 {
                  bw.write("          <border top=""" & 
                           format.getBorder(Border.TOP).getDescription() & """");
                  bw.newLine();
                  bw.write("                  bottom=""" & 
                           format.getBorder(Border.BOTTOM).getDescription() & 
                           """");
                  bw.newLine();
                  bw.write("                  left=""" & 
                           format.getBorder(Border.LEFT).getDescription() & """");
                  bw.newLine();
                  bw.write("                  right=""" & 
                           format.getBorder(Border.RIGHT).getDescription() & """");
                  bw.write(" />");
                  bw.newLine();
                }

                // The cell number/date format
                if (NOT format.getFormat().getFormatString().toString() eq '')
                {
                  bw.write("          <format_string string=""");
                  bw.write(format.getFormat().getFormatString());
                  bw.write(""" />");
                  bw.newLine();
                }

                bw.write("        </format>");
                bw.newLine();
              }

              bw.write("      </col>");
              bw.newLine();
            }
          }
          bw.write("    </row>");
          bw.newLine();
        }
        bw.write("  </sheet>");
        bw.newLine();
      }
      
      bw.write("</workbook>");
      bw.newLine();
      bw.flush();
      bw.close();
   // }
//    catch (UnsupportedEncodingException e)
 //   {
  //    System.err.println(e.toString());
   // }
	</cfscript>

<cfoutput>#out#</cfoutput>